package com.kgc.jy91.springboot1.autoConfiguration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @program: springboot1
 * @description
 * @author: wanggang
 * @create: 2020-12-16 16:05
 **/
@Configuration
@EnableConfigurationProperties({SayHelloProperties.class})
@ConditionalOnClass({SayHello.class})
@ConditionalOnProperty(
        prefix = "hello",
        value = {"enabled"},
        matchIfMissing = true)
public class SayHelloAutoConfiguration {
    @Autowired
    private SayHelloProperties sayHelloProperties;

    @Bean
    @ConditionalOnMissingBean({SayHello.class})
    public SayHello sayHello(){
        SayHello sayHello= new SayHello();
        sayHello.setMsg(sayHelloProperties.getHelloMsg());
        return  sayHello;

    }

}
